import Vue from 'vue'

export const eventBus = new Vue()

export function splitTitle(oldTitle) {
  let start_, start, end, newTitle, opera
  start = oldTitle.indexOf('(') === -1 ? oldTitle.indexOf('（') : oldTitle.indexOf('(')
  end = oldTitle.indexOf(')') === -1 ? oldTitle.indexOf('）') : oldTitle.indexOf(')')
  if (start !== -1 && end !== -1) {
    start_ = start + 1
    opera = oldTitle.substring(start_, end)
    newTitle = oldTitle.substring(0, start)
    return {opera, newTitle}
  } else {
    opera = ''
    newTitle = ''
    return {opera, newTitle}
  }
}

export function startGame(url) {
  if (this.PC) {
    if (Vue.userInfo.length !== 0) {
      this.$router.push({path: '/PCGame', query: {gameUrl: url}})
    } else {
      this.eventBus.$emit('pcLogin', true)
    }
    return false
  } else if (Vue.userInfo.length === 0) {
    this.$router.push({path: '/phoneLogin'})
    return false
  }
  window.location.href = url
}

export function closePhoneBox() {
  this.$router.go(-1)
}
